﻿using BotDetector.Core;
using BotDetector.Web.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Helpers;
using System.Web.Http;
using System.Web.Http.Results;

namespace BotDetector.Web.Controllers
{
    public class RestController : ApiController
    {
        [HttpPost]
        public JsonResult<Message> Submit(JObject json)
        {
            string value = (string)json["Text"];

            Message message = new Message();
            message.Text = value;
            if (value.Length > 0)
            {
                message.BotProbability = DetectorCreator.Detector.Classify(value);
            }
            else
            {
                message.BotProbability = 0;
            }
            return Json<Message>(message);
        }
    }
}
